﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

class InfluenceMG
{
    public static string INFLUENCE_EGG = "Egg";
    public static string INFLUENCE_OTHER = "Other";
    public static string INFLUENCE_FOLK = "Folk";
    public static string INFLUENCE_BLACKMARK = "BlackMark";
    public static string INFLUENCE_PLAYER4 = "Player4";
    public static string INFLUENCE_PLAYER3 = "Player3";
    public static string INFLUENCE_PLAYER2 = "Player2";
    public static string INFLUENCE_PLAYER = "Player";
    public static string INFLUENCE_FIRE_STAR = "FireStarHuman";
    public static string INFLUENCE_EARTH = "EearthHuman";

    static InfluenceMG m_Instance = new InfluenceMG();
    List<Influence> m_Influences = new List<Influence>();
    List<Influence> m_PlayerInfluences = new List<Influence>();
    public static InfluenceMG get()
    {
        return m_Instance;
    }

    public bool isHostile(string self, string other)
    {
        var selfInfluence = find(self);
        if (selfInfluence == null)
        {
            return false;

        }
        int hostileIndex = selfInfluence.findHostile(other);
        return hostileIndex >= 0;
    }

    public void Init()
    {
        Influence player = new Influence(INFLUENCE_PLAYER);
        Influence player2 = new Influence(INFLUENCE_PLAYER2);
        Influence player3 = new Influence(INFLUENCE_PLAYER3);
        Influence player4 = new Influence(INFLUENCE_PLAYER4);

        Influence fireStar = new Influence(INFLUENCE_FIRE_STAR);
        Influence earth = new Influence(INFLUENCE_EARTH)    ;
        add(player);
        add(player2);
        add(player3);
        add(player4);
        add(fireStar);
        add(earth);
        m_PlayerInfluences.Add(player);
        m_PlayerInfluences.Add(player2);
        m_PlayerInfluences.Add(player3);
        m_PlayerInfluences.Add(player4);
        player.addHostileInfluence(fireStar.Name);
        player.addHostileInfluence(player2.Name);
        player.addHostileInfluence(player3.Name);
        player.addHostileInfluence(player4.Name);

        player2.addHostileInfluence(player.Name);
        player2.addHostileInfluence(player3.Name);
        player2.addHostileInfluence(player4.Name);

        player3.addHostileInfluence(player.Name);
        player3.addHostileInfluence(player2.Name);
        player3.addHostileInfluence(player4.Name);

        player4.addHostileInfluence(player.Name);
        player4.addHostileInfluence(player2.Name);
        player4.addHostileInfluence(player3.Name);

        earth.addHostileInfluence(fireStar.Name);
        fireStar.addHostileInfluence(earth.Name);
        fireStar.addHostileInfluence(player.Name);
    }
    public bool IsPlayer(string influence)
    {
        foreach(var playeri in m_PlayerInfluences)
        {
            if(playeri.Name == influence)
            {
                return true;
            }
        }
        return false;
    }
    public string GetPlayer(int index)
    {
        index = Mathf.Clamp(index, 0, m_PlayerInfluences.Count);
        return m_PlayerInfluences[index].Name;
    }

    public void add(Influence influence)
    {
        m_Influences.Add(influence);
    }

    public Influence find(string influenceName)
    {
        for(int i=0; i< m_Influences.Count; ++i)
        {
            if(m_Influences[i].Name == influenceName)
            {
                return m_Influences[i];
            }
        }
        return null;
    }

    public void Clear()
    {
        m_Influences.Clear();
    }
}